package com.zyx.demo.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.Map;

/**
 * @author zyx
 * @version 1.0
 * @date 2022/1/6 006 8:52
 * 读取excel数据
 */

public class ExcelRead extends AnalysisEventListener<DemoData> {
    /**
     *一行一行读取excel数据
     * @param demoData
     * @param analysisContext
     */
    @Override
    public void invoke(DemoData demoData, AnalysisContext analysisContext) {
        System.out.println("**********" + demoData);
    }

    /**
     * 读取表头
     * @param headMap
     * @param context
     */
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println("表头 " + headMap);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    public static void main(String[] args) {
        String filename = "D:/vs/write.xlsx";
        EasyExcel.read(filename,DemoData.class,new ExcelRead()).sheet().doRead();
    }
}
